from typing import Annotated
from fastapi import APIRouter, Body
from loguru import logger

from app.config.settings import CONFIG
from app.model.user import AlgParam

router = APIRouter(prefix="/alg", tags=["alg"])


# 算法健康检查
@router.get("/alg_state/probe")
def probe():
    res = {"code": 0, "message": "操作成功"}
    return res


# 算法运行状态
@router.get("/alg_state/infos")
def infos():
    datas = []
    for i in range(1, 3):
        data = {
            "name": f"thread{i}",
            "state": 0,
            "device_no": "10010",
            "alg_type": "smoke",
            "camera_type": 1,
            "video_url": "rtsp://192.168.2.230/10010/000100",
            "video_type": 1,
        }
        datas.append(data)
    res = {"code": 0, "message": "操作成功", "data": datas}
    return res


# 算法设置参数
@router.post("/alg_param/set")
def paramset(item: Annotated[AlgParam, Body()]):
    logger.info(f"device_no={item.device_no}")
    res = {"code": 0, "message": "操作成功"}

    # client = TestClient(FastAPI())
    manager_service = CONFIG['alg']['manager_service']
    logger.info(f"manager_service={manager_service}")
    return res
